﻿using System;
using JTLeigh.Commerce.Spencer.Core.Common;

namespace JTLeigh.Commerce.Spencer.Features.ProductImages.Common.Entities
{

	/// <summary>
	/// Wraps a product image size and an optional localization, and exposes properties from these 
	/// objects with fallback when the objects are <see langword="null"/>.
	/// </summary>
	public class LocalizedProductImageSize
	{

		#region Fields

		private ProductImageSize _size;
		private ProductImageSizeLocalization _localization;

		#endregion // Fields

		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="LocalizedProductImageSize"/> class with 
		/// the specified size and localization.
		/// </summary>
		/// <param name="size">The <see cref="ProductImageSize"/> to wrap.</param>
		/// <param name="localization">The <see cref="ProductImageSizeLocalization"/> to wrap, or
		/// <see langword="null"/> if no localization was found.</param>
		public LocalizedProductImageSize(ProductImageSize size, ProductImageSizeLocalization localization)
		{
			Safety.AssertArgumentNotNull("size", size);
			// localization can be null

			_size = size;
			_localization = localization;
		}

		#endregion // Constructors

		#region Properties

		/// <summary>
		/// Gets the size identifier.
		/// </summary>
		/// <value>A size identifier <see cref="Guid"/>.</value>
		public Guid SizeId
		{
			get { return _size.SizeId; }
		}

		/// <summary>
		/// Gets the well-known size code.
		/// </summary>
		/// <value>A well-known size code <see cref="Byte"/>.</value>
		public byte WellKnownSizeCode
		{
			get { return _size.WellKnownSizeCode; }
		}

		/// <summary>
		/// Gets the width of the image.
		/// </summary>
		/// <value>An <see cref="Int16"/> pixel width.</value>
		public short Width
		{
			get { return _size.Width; }
		}

		/// <summary>
		/// Gets the height of the image.
		/// </summary>
		/// <value>An <see cref="Int16"/> pixel height.</value>
		public short Height
		{
			get { return _size.Height; }
		}

		/// <summary>
		/// Gets the order in which the size should be displayed.
		/// </summary>
		/// <value>An <see cref="Int32"/> ordinal position.</value>
		public int DisplayOrder
		{
			get { return _size.DisplayOrder; }
		}

		/// <summary>
		/// Gets the name of the size.
		/// </summary>
		/// <value>If a localization was provided, the localization's name.  Otherwise, the size's
		/// default name.</value>
		public string Name
		{
			get
			{
				return (_localization != null) ? _localization.Name : _size.DefaultName;
			}
		}

		/// <summary>
		/// Gets the missing image path for the size.
		/// </summary>
		/// <value>If a localization was provided, the localization's missing image path.  
		/// Otherwise, the size's default missing image path.</value>
		public string MissingImagePath
		{
			get
			{
				return (_localization != null) ? _localization.MissingImagePath : _size.DefaultMissingImagePath;
			}
		}

		#endregion // Properties

	}

}
